import clone from '@feidao/web/atom/core/obj/clone';
import { query2obj, generate } from '@feidao/core/querystring';
import { Params } from './params2query';

export default function generate_sort_fields(url: string, query: Params, fields: string[]) {
	return fields.map((field) => {
		const tmp = clone(query);
		tmp.order = {};	// ! 如果需要多个排序条件，去掉这一行代码即可
		tmp.order[field] = true;
		const asc = generate(tmp, url);
		tmp.order[field] = false;
		const desc = generate(tmp, url);
		return {
			asc,
			desc,
			field
		}
	});
}
